import pathToRegexp from 'path-to-regexp/index';
import {getAllemerg,getADDaddress,getADDmaterial,getMaillist,postAllemerg,getAllemergList,getAllemergListTow,getAllRoleOne} from 'services/app';
import { routerRedux } from 'dva/router';

export default {
    namespace: 'Allemerg',
    state: {
        pages:1,
        record:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //获取巡检点列表
        *getAllemerg ({ payload }, { call, put }){
            const {data,total} = yield call(getAllemerg, payload);
            yield put({ type: 'save', payload: {getAllemergData:data,total:total,pages:payload.pageNumber}});
        },
        //新增之前
        *newPost ({ payload }, { call, put }){
            const data = yield call(getADDaddress, payload);
            const dataTow = yield call(getADDmaterial, payload);
            const datathrid = yield call(getAllRoleOne, {o_id:'111111'});//部门
            // const datathrid = yield call(getMaillist, {
            //     name:"",
            //     phone :"",
            //     pageNumber :0,
            //     pageSize :0,
            // });
            yield put({ type: 'save', payload: {YJDZ:data.data,TXL:datathrid.data,YJWZ:dataTow.data}});
        },
        //新增
        *postAllemerg ({ payload }, { call, put }){
            const data = yield call(postAllemerg, payload);
            if (data.code == 0){
                yield put({ type: 'save', payload: {view:false,pages:0}});
            }
        },
        //查详情
        *getAllemergList ({ payload }, { call, put }){
            const {data} = yield call(getAllemergList, payload);
            yield put({ type: 'save', payload: {getAllemergListData:data}});
        },
        //查详情2
        *getAllemergListTow ({ payload }, { call, put }){
            const {data} = yield call(getAllemergListTow, payload);
            yield put({ type: 'save', payload: {getData:data}});
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
